﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DynamicProperties;

namespace DynamicProperties.Tests
{
	[TestClass]
	public class DynamicPropertyTests
	{
		int globalUniqueNumberCountOriginal;

		[TestInitialize]
		public void TestInit()
		{
			this.globalUniqueNumberCountOriginal = DynamicProperty_Accessor.globalUniqueNumberCount;
		}

		[TestCleanup]
		public void TestCleanup()
		{
			DynamicProperty_Accessor.globalUniqueNumberCount = this.globalUniqueNumberCountOriginal;
		}

		[TestMethod]
		public void EqualTestSuccess()
		{
			var dp1 = new DynamicProperty<object, object>("Test property 1");

			bool result = dp1.Equals(dp1);

			Assert.IsTrue(result);
		}

		[TestMethod]
		public void EqualTestFail()
		{
			var dp1 = new DynamicProperty<object, object>("Test property 1");
			var dp2 = new DynamicProperty<object, object>("Test property 2");

			bool result = dp1.Equals(dp2);

			Assert.IsFalse(result);
		}

		[TestMethod]
		public void EqualTestFailNull()
		{
			var dp1 = new DynamicProperty<object, object>("Test property 1");

			bool result = dp1.Equals(null);

			Assert.IsFalse(result);
		}

		[TestMethod]
		[ExpectedException(typeof(Exception))]
		public void UniqueIdGenerationLimit()
		{
			DynamicProperty_Accessor.globalUniqueNumberCount = DynamicProperty_Accessor.globalUniqueNumberMax;

			DynamicProperty_Accessor.GetGlobalUniqueNumber();
		}
	}
}
